package JCT_Chapter_03;

import java.util.*;

public class Test_Array {
    public static void main(String[] args)  {
        //
        int[] a = new int[100];
        for(int i = 0; i < a.length; i++)  {
            a[i] = i + 1;
            if(a[i] == 23) {
                System.out.println(a[i]);
            }
        }
        //定义一个字符串数组，其中的元素将被初始化为null
        String[] names = new String[10];
        System.out.println(names[0]);
        //将这个字符串数组赋值为空串，此时这个字符串数组将分配得到内存空间
        for(int i = 0; i < names.length; i++)   {
            names[i] = "";
        }
        System.out.println(names[0] + "Hello!");
        //for-each循环
        for(int element : a)    {
            System.out.println(element);
        }
        //返回一个包含数组元素的字符串
        System.out.println(Arrays.toString(a));
        String b = Arrays.toString(a);
        System.out.println(b);
        //比较简洁的数组定义方式
        int[] smallPrimes = {1,2,3,4,5,6,7,8,9,10};
        //首先声明一个整数型数组，利用赋值的方式进行定义
        int[] bigPrimes = smallPrimes;
        for(int element : smallPrimes)  {
            System.out.println(element);
        }
        for(int element : bigPrimes)   {
            System.out.println(element);
        }
        int[] luckyNumbers = smallPrimes;
        //改变luckynumbers[5]的值，此时smallPrimes[5]的值也为12
        luckyNumbers[5] = 12;
        System.out.println(Arrays.toString(luckyNumbers));
        smallPrimes[6] = 17;
        System.out.println(Arrays.toString(smallPrimes));
        int[] copidluckyNumbers = Arrays.copyOf(luckyNumbers,luckyNumbers.length);
        System.out.println(Arrays.toString(copidluckyNumbers));
        int[] luckyNumbers2 = Arrays.copyOf(luckyNumbers,2 * luckyNumbers.length);
        System.out.println(Arrays.toString(luckyNumbers2));
    }
}
